using TMPro;
using UnityEngine;
using UnityEngine.UI;
using TEngine;
using UnityEngine.Events;

namespace GameLogic
{
	partial class MapIcon
	{
		StarSphere m_StarSphere;

        UnityEvent<StarSphere> m_OnClickCallback = new UnityEvent<StarSphere>();

        float m_Scale = 1;
        public UnityEvent<StarSphere> OnClickCallback { get => m_OnClickCallback;  }
        Image m_imgPreview;
        #region 
        protected override void OnCreate()
        {
            base.OnCreate();
            m_imgPreview = m_btnExClick.GetComponent<Image>();
        }
        protected override void RegisterEvent()
        {
            base.RegisterEvent();
            m_btnExClick.tweenWhenClick = false;
            m_btnExClick.AddClickEvent(() => {
                GameModule.UI.ShowUI<FloatingTips>("Clicked on :" + m_StarSphere.name);
                m_OnClickCallback.Invoke(m_StarSphere);
            });
        }
        public void Bind(StarSphere sphere)
		{
			m_StarSphere = sphere;

            var sssp = m_StarSphere.GetComponent<SpriteRenderer>();
            if(sssp)
            {
                m_imgPreview.sprite = sssp.sprite;
                m_imgPreview.alphaHitTestMinimumThreshold = 0.1f;
            }

            m_Scale = Mathf.Clamp( sphere.transform.localScale.x / 1000, 0.1f, 100);
        }

        /// <summary>
        /// 窗口更新
        /// </summary>
        protected override void OnUpdate()
        {
            transform.localPosition = m_StarSphere.transform.localPosition * 0.05f;
            transform.localScale = new Vector3(m_Scale, m_Scale, 0);
            //transform.localScale = new Vector3(1f / transform.parent.localScale.x * m_Scale, 1f / transform.parent.localScale.y * m_Scale, 0);
        }
        #endregion
    }
}